package spe.ui.command.handler;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
//import org.eclipse.core.commands.IHandler;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.navigator.CommonNavigator;

import spe.ui.wizard.NewMethodLibraryWizard;

public class NewMethodLibrary extends AbstractHandler //implements IHandler
{
	@Override
	public Object execute(ExecutionEvent ee) throws ExecutionException 
	{
		IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(ee);
		NewMethodLibraryWizard wizard = new NewMethodLibraryWizard();
		
		IWorkbenchPage page = window.getActivePage();
		CommonNavigator view = (CommonNavigator)page.findView("spe.ui.navigator.view");
		ISelection selection = null;
		
		if(view != null)
		{
			selection = view.getSite().getSelectionProvider().getSelection();
			if(selection instanceof IStructuredSelection)
				wizard.init(window.getWorkbench(), (IStructuredSelection)selection);
		}
		
		WizardDialog wd = new WizardDialog(window.getShell(), wizard);
		wd.open();
		return null;
	}

}
